package com.rogo.oauth
{
	import flash.net.URLVariables;
	
	/**
	 * URL Request 参数
	 * 
	 * @author Rogo
	 */	
	public class URLParams
	{
		public function URLParams()
		{
			params = new Array();
		}
		
		//--------------------------------------------------------------------------
		//
		//  Varaibles
		//
		//--------------------------------------------------------------------------
		
		private var params:Array;
		
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		public function addParam(param:URLParam):void
		{
			params.push(param);
		}
		
		public function toBaseParams():String
		{
			var baseParams:String = null;
			
			// 排序
			params.sortOn('paramName');
			
			for each (var param:URLParam in params)
			{
				baseParams = baseParams ? (baseParams + '%26') : '';
				baseParams += param.baseString;
			}
			
			return baseParams;
		}
		
		public function toURLVariables():URLVariables
		{
			var urlVar:URLVariables = new URLVariables();
			
			for each (var param:URLParam in params)
			{
				urlVar[param.paramName] = param.paramValue;
			}
			
			return urlVar;
		}
		
	}
}